<template>
<div class="wallet-cash-create">
	<Row>
		<Col :span="24">
			<Breadcrumb>
				<BreadcrumbItem to="/" @click.native="changeMenu(0)"><Icon type="home"></Icon> 首页</BreadcrumbItem>
				<BreadcrumbItem :to="{'name':'wallet-cash-index'}">提现管理</BreadcrumbItem>
				<BreadcrumbItem>{{title}}</BreadcrumbItem>
			</Breadcrumb>
			<div class="cleaner20"></div>
		</Col>
	</Row>
	<Form ref="vform" :model="vform" :label-width="100" :rules="ruleValidate">
		<Row type="flex" :gutter="0">
			<Col :span=8>
				<Row type="flex">
					<Col :span="24">
						<FormItem ref="realname" label="用户名称" prop="realname">
							<Input v-model="vform.realname" placeholder="请填写用户名称" readonly>
								<Icon type="md-search" slot="suffix" @click.native="onSelectUser"></Icon>
							</Input>
						</FormItem>
					</Col>
					<Col :span="24">
						<FormItem label="状态" prop="status">
							<Select v-model="vform.status" >
								<Option v-for="(item,index) in statusList" :value="item.value" :key="index">{{ item.label }}</Option>
							</Select>
						</FormItem>
					</Col>
					<Col :span="24">
						<FormItem label="提现金额" prop="total">
							<InputNumber :max="99999" :min="0" :step="0.01" v-model="vform.total"></InputNumber>
						</FormItem>
					</Col>
					<Col :span="24">
						<FormItem label="到账金额" prop="actual_total">
							<InputNumber :max="99999" :min="0" :step="0.01" v-model="actual_total"></InputNumber>
						</FormItem>
					</Col>
					<Col :span="24">
						<FormItem label="手续费" prop="fee">
							<InputNumber :max="99999" :min="0" :step="0.01" v-model="vform.fee"></InputNumber>
						</FormItem>
					</Col>
					<Col :span="24">
						<FormItem label="银行账号" prop="account">
							<Input v-model="vform.account"></Input>
						</FormItem>
					</Col>
					<Col :span="24">
						<FormItem label="银行名称" prop="bank">
							<Input v-model="vform.bank"></Input>
						</FormItem>
					</Col>
					<Col :span="24">
						<FormItem label="支行名称" prop="branch">
							<Input v-model="vform.branch"></Input>
						</FormItem>
					</Col>
					<Col :span="24">
						<FormItem label="备注">
							<Input v-model="vform.memo" placeholder="请填写备注"></Input>
						</FormItem>
					</Col>
					<Col :span="24">
						<FormItem label="">
							<Button type="success" @click="onSave">保存</Button>
						</FormItem>
					</Col>
				</Row>
			</Col>
	
		</Row>
	</Form>

	<Listener-Selector  :show.sync="showBox" @on-hide="showBox=false" @on-change="onListenerChange"></Listener-Selector>
	

</div>
</template>
<script>
// 引入子组件
import ListenerSelector from '@/components/ListenerSelector/ListenerSelector.vue'
import {mapState,mapGetters} from 'vuex'
import { Tag, Card, Page, Modal, Spin, Row, Col, ButtonGroup, Button,  Breadcrumb, BreadcrumbItem, Icon, Form, FormItem, Input, Select, Option, DatePicker, InputNumber } from 'iview';
export default { 
	name:'wallet-cash-create',
	components: { Tag, Card, Page, Modal, ListenerSelector, Spin, Row, Col, ButtonGroup, Button, Breadcrumb, BreadcrumbItem, Icon, Form, FormItem, Input, Select, Option, DatePicker, InputNumber},
	data () {
		return {
			title:'新建',
			showBox:false,
			spinShow:false,
			listenerObj:{},
			
			ruleValidate: {
				realname: [
					{ required: true, message: '请选择倾听者', trigger: 'blur' },
				],
				status: [
					{ required: true, message: '请选择状态', trigger: 'change', type:'number' }
				],
				fee: [
					{ required: true, message: '请填写手续费', trigger: 'change', type:'number' }
				],
				total: [
					{ required: true, message: '请填写提现金额', trigger: 'change', type:'number' },
					{ min: 100, message: '提现金额最低100', trigger: 'change', type:'number' }
				],
				actual_total: [
					{ required: true, message: '请填写到账金额', trigger: 'change', type:'number'},
					{ min: 80, message: '提现金额最低80', trigger: 'change', type:'number' }
				],
				account: [
					{ required: true, message: '请填写银行账号', trigger: 'blur'}
				],
				bank: [
					{ required: true, message: '请填写银行名称', trigger: 'blur'}
				],
				branch: [
					{ required: true, message: '请填写支行名称', trigger: 'blur'}
				],
				
			},
			vform:{
				realname:'',
				status:0,
				account:'',
				total:0,
				fee:0,
				actual_total:0,
				bank:'',
				brach:'',
				uid:null,
				memo:''
			},
			statusList: [
				{value: 0,label: '待处理'},
				{value: 1,label: '提现成功'},
				{value: 2,label: '提现失败'},
			],
			
			
		}
	},
	methods:{
		init:function(){
		},
		onSave:function(index){
			let self=this
			let _flag=true
			this.$refs.vform.validate((valid) => {
				if (!valid){
					this.$Message.error('请完成必填项')
					_flag=false
				}
			})
			if(!_flag){return}
			self.$store.dispatch("setSpinShow",true)
			self.$http.post("/v1/wallet/cashes?token="+self.token,{'data':JSON.stringify(self.vform)})
			.then(function(response){
				if(200==response.data.status && 0==response.data.code)
				{
					self.$Message.success('操作成功')
					self.$router.push({path:'/wallet/cash/edit/'+response.data.data.id})
				}else{
					self.$Message.error(response.data.message)
				}
				self.$store.dispatch("setSpinShow",false)
			}).catch(function(error){
				self.$Message.error(error.message)
				self.$store.dispatch("setSpinShow",false)
			})
		},
		onSelectUser:function(){
			this.showBox=true
		},
		onListenerChange:function(obj){
			this.listenerObj=obj
			this.vform.uid=this.listenerObj.uid
			this.vform.realname=this.listenerObj.realname
		},
	},
	created:function(){
	},
	mounted () {
		this.init()
    	this.setTitle(this.title)
	},
	activated:function(){
	},
	computed:{
		...mapGetters(['token','menuIndex']),
		actual_total:{
			get(){this.vform.actual_total=this.vform.total-this.vform.fee
			return this.vform.total-this.vform.fee},
			set(val){this.vform.actual_total=val}
		}
	},
}



</script>
<style lang="less" scoped>
</style>